package org.jsola.contract.constant;

import org.jsola.core.validator.IConst;
import org.jsola.json.JsonKit;

import java.util.HashMap;
import java.util.Map;

/**
 * 个人签章类型
 *
 * @author JanusMix
 */
public enum PersonSealType implements IConst {

    /**
     * 正方形印章
     */
    SQUARE("SQUARE","正方形印章"),
    /**
     * 矩形印章
     */
    RECTANGLE("RECTANGLE","矩形印章"),
    /**
     * 艺术字体印章1
     */
    FZKC("FZKC","艺术字体印章1"),
    /**
     * 艺术字体印章2
     */
    YYGXSF("YYGXSF","艺术字体印章2"),
    /**
     * 艺术字体印章3
     */
    HYLSF("HYLSF","艺术字体印章3"),
    /**
     * 无框矩形印章
     */
    BORDERLESS("BORDERLESS","无框矩形印章"),
    /**
     * 华文隶书
     */
    HWLS("HWLS","华文隶书"),
    /**
     * 华文行楷
     */
    HWXK("HWXK","华文行楷"),
    /**
     * 带框华文行楷
     */
    HWXKBORDER("HWXKBORDER","带框华文行楷"),
    /**
     * 叶根友疾风草书
     */
    YGYJFCS("YGYJFCS","叶根友疾风草书"),
    /**
     * 叶根友行书
     */
    YGYMBXS("YGYMBXS","叶根友行书");

    private final String value;
    private final String desc;
    /**
     * 枚举值罗列，给swagger接口文档展示用
     */
    public static final String VALUES_STR = "SQUARE,RECTANGLE,FZKC,YYGXSF,HYLSF,BORDERLESS,HWLS,HWXK,HWXKBORDER,YGYJFCS,YGYMBXS";

     /**
     * 缓存所有value
     */
    private static final Map<String, PersonSealType> LOOKUP = new HashMap<>();

    static {
        for (PersonSealType e : PersonSealType.values()) {
            LOOKUP.put(e.value, e);
        }
    }


    PersonSealType(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    /**
     * 根据value查找PersonSealType
     * @param value value
     * @return PersonSealType
     */
    public static PersonSealType find(String value) {
        return LOOKUP.get(value);
    }

    /**
     * 根据desc查找PersonSealType
     * @param desc desc
     * @return PersonSealType
     */
    public static PersonSealType findByDesc(String desc){
        for (PersonSealType e : PersonSealType.values()) {
            if(e.getDesc().equals(desc)){
                return e;
            }
        }
        return null;
    }

    /**
     * 所有枚举转json
     * @return json
     */
    public static String getAllToJson() {
        Map<String,Object> map = new HashMap<>();
        for (PersonSealType e : PersonSealType.values()) {
            map.put("value", e.value);
            map.put("desc", e.desc);
        }
        return JsonKit.toJSONString(map);
    }

    @Override
    public boolean check(Object obj) {
        String value = (String) obj;
        return find(value) != null;
    }

    public String getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }
}
